package com.atguigu.lease.common.config;

//import com.atguigu.lease.common.convert.FacilitiyInfoTypeEnumConverter;
import com.atguigu.lease.common.convert.BaseTypeEnumConverterFactory;
import com.atguigu.lease.model.enums.FacilityInfoTypeEnum;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *  WebMvcConfigurer springmvc提供的 用来动态注册组件类 或者动态配置的 配置类
 *
 */
@Configuration
public class StgyWebMvcConfiguration implements WebMvcConfigurer {
    //1、注册springmvc拦截器的方法
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
////        WebMvcConfigurer.super.addInterceptors(registry);
//        registry.addInterceptor()
//                .addPathPatterns();
//    }

    //2、springmvc提供的 跨域配置
//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
////        WebMvcConfigurer.super.addCorsMappings(registry);
//        registry.addMapping()
//
//    }
//    @Resource
//    FacilitiyInfoTypeEnumConverter facilitiyInfoTypeEnumConverter;
    @Resource
    BaseTypeEnumConverterFactory baseTypeEnumConverterFactory;
    //3、springmvc提供的 注册 参数转换器的配置
    @Override
    public void addFormatters(FormatterRegistry registry) {
//        WebMvcConfigurer.super.addFormatters(registry);
        //注册单个的类型转换器
//        registry.addConverter(facilitiyInfoTypeEnumConverter);
        //注册类型转换器工厂： 类型转换工厂对象 会在服务器启动时，初始化父接口所有实现类对应的转换器注入到容器中
        registry.addConverterFactory(baseTypeEnumConverterFactory);
    }
}
